﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dzzzr
{
	/// <summary>
	/// Editor for UserToRoles
	/// </summary>
	public class UserToRolesCollectionEditor : System.ComponentModel.Design.CollectionEditor
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="type"></param>
		public UserToRolesCollectionEditor(Type type)
			: base(type)
		{
		}

		/// <summary>
		/// Create new object
		/// </summary>
		/// <param name="itemType"></param>
		/// <returns></returns>
		protected override object CreateInstance(Type itemType)
		{
			UserToRole ur = (UserToRole)base.CreateInstance(itemType);
			if (this.Context.Instance is User)
			{
				ur.User = this.Context.Instance as User;

				DBDataContext.DataContext.UserToRoles.InsertOnSubmit(ur);
			}
			return ur;
		}

		/// <summary>
		/// Delete object
		/// </summary>
		/// <param name="instance"></param>
		protected override void DestroyInstance(object instance)
		{
			base.DestroyInstance(instance);
			DBDataContext.DataContext.UserToRoles.DeleteOnSubmit(instance as UserToRole);
		}
	}
}
